package cn.dengta.webapp.im.entity;

import java.util.Date;

import cn.dengta.common.model.Status;
import cn.dengta.webapp.base.entity.TimeBasedEntity;
import com.baomidou.mybatisplus.annotation.TableName;
import lombok.Getter;
import lombok.Setter;
import lombok.experimental.Accessors;
import me.codeplayer.util.RandomUtil;

/**
 * 缘分雷达速配日志表
 *
 * @author lgy
 * @since 2022-07-23
 */
@Setter
@Getter
@Accessors(chain = true)
@TableName("im_fate_radar_log")
public class FateRadarLog extends TimeBasedEntity {

	public static String DEFAULT_SLOGAN = "If we fell in love again I swear love your right";

	/** 用户ID */
	private Long userId;
	/** 被推荐ID */
	private Long toUserId;
	/** 匹配指数 */
	private Integer matchNum;
	/** 状态：-1=尚未匹配；0=已匹配未搭讪；1=已搭讪 */
	private Integer toStatus;
	/** 状态：-1=尚未匹配；0=已匹配未搭讪；1=已搭讪 */
	private Integer status;
	/** 简介（没有设置时默认展示） */
	private String slogan;
	/** 消耗钻石 */
	private Integer coin;

	public FateRadarLog init(Long userId, Long toUserId, Integer status, Integer toStatus, Date now) {
		this.userId = userId;
		this.toUserId = toUserId;
		this.toStatus = toStatus;
		this.status = status;
		super.initTime(now);
		return this;
	}

	public void exchangeStatus(FateRadarLog toUserLog, Integer status) {
		this.setStatus(status).setToStatus(toStatus);
		toUserLog.setStatus(toStatus).setToStatus(status);
	}

	public static int calcMatchNum(boolean isCommon) {
		int min = isCommon ? 90 : 80;
		return RandomUtil.getInt(min, min + 9);
	}

	public boolean isPaired() {
		return status >= 0;
	}

	public boolean greeted() {
		return Status.asResult(status) || Status.asResult(toStatus);
	}

	public static final String USER_ID = "user_id";
	public static final String TO_USER_ID = "to_user_id";
	public static final String SLOGAN = "slogan";
	public static final String TO_STATUS = "to_status";
	public static final String STATUS = "status";

}
